package org.apache.solr.schema;


import java.util.Map;
import org.apache.lucene.spatial.prefix.RecursivePrefixTreeStrategy;

/**
 * @see RecursivePrefixTreeStrategy
 * @lucene.experimental
 */
public class SpatialRecursivePrefixTreeFieldType extends AbstractSpatialPrefixTreeFieldType<RecursivePrefixTreeStrategy> {

    /**
     * @see RecursivePrefixTreeStrategy#setPrefixGridScanLevel(int)
     */
    public static final String PREFIX_GRID_SCAN_LEVEL = "prefixGridScanLevel";
    private Integer prefixGridScanLevel;

    @Override
    protected void init(IndexSchema schema, Map<String, String> args) {
        super.init(schema, args);

        String v = args.remove(PREFIX_GRID_SCAN_LEVEL);
        if (v != null) {
            prefixGridScanLevel = Integer.valueOf(v);
        }
    }

    @Override
    protected RecursivePrefixTreeStrategy newPrefixTreeStrategy(String fieldName) {

        RecursivePrefixTreeStrategy strategy = new RecursivePrefixTreeStrategy(grid, fieldName);
        if (prefixGridScanLevel != null) {
            strategy.setPrefixGridScanLevel(prefixGridScanLevel);
        }
        return strategy;
    }
}
